package org.edu.eece262.taskshare;

import java.io.Serializable;
import java.util.LinkedList;

public class Messages {
	public enum ActionType {
		POLL, LOGOUT, CREATEUSER, LOGIN, GETCONTACTS, ADDCONTACT, ADDTASK, 
		UPDATETASK, DELETETASK, GETTASKS, ASSIGNTASK, CREATEGROUP, JOINGROUP, MODIFYGROUP, 
		ASSIGNTOGROUPONESHOT, ASSIGNTOGROUPMULTIPLECOMPLETION, DELETECONTACT, SEARCHCONTACT, 
		SEARCHGROUPS, DELETEGROUP
	};
	
	public enum ResponseType {
		SUCCESS, FAILURE, ONHOLD, FAILURENOTLOGGEDIN, FAILURENOTPERMITTED
	};
	
	public static class User implements Serializable {

		private static final long serialVersionUID = -1625180246859609066L;
		
		private String username;
		private String phonenumber;
		private String email;
		private String name;
		
		public String getUsername() {
			return username;
		}
		public void setUsername(String username) {
			this.username = username;
		}
		public String getPhonenumber() {
			return phonenumber;
		}
		public void setPhonenumber(String phonenumber) {
			this.phonenumber = phonenumber;
		}
		public String getEmail() {
			return email;
		}
		public void setEmail(String email) {
			this.email = email;
		}
		public String getName() {
			return name;
		}
		public void setName(String name) {
			this.name = name;
		}
		
	}
	
	public static class GroupMember implements Serializable {

		private static final long serialVersionUID = -1616421818191766456L;
		
		private String groupMemberUser;
		
		public static class StatusType {
	    	public static final int ACTIVE = 0;
	    	public static final int REQUESTED = 1;
	    	public static final int WAITING = 2; 
	    	public static final int ACCEPTED = 3;
	    	public static final int DELTETED = 4;
	    }
		
		private int groupMemberStatus;
		
		public static class RollType {
	    	public static final int OWNER = 0;
	    	public static final int ADMIN = 1;
	    	public static final int USER = 2; 
	    }
	    
	    private int groupMemberRoll;
	    
	    public GroupMember(String username, int Status, int Roll) {
	    	this.groupMemberUser = username;
	    	this.groupMemberStatus = Status;
	    	this.groupMemberRoll = Roll;
	    }
	    
		public String getGroupMemberUser() {
			return groupMemberUser;
		}


		public void setGroupMemberUser(String groupMemberUser) {
			this.groupMemberUser = groupMemberUser;
		}


		public int getGroupMemberStatus() {
			return groupMemberStatus;
		}


		public GroupMember setGroupMemberStatus(int groupMemberStatus) {
			this.groupMemberStatus = groupMemberStatus;
			return this;
		}


		public int getGroupMemberRoll() {
			return groupMemberRoll;
		}


		public void setGroupMemberRoll(int groupMemberRoll) {
			this.groupMemberRoll = groupMemberRoll;
		}
	}

	public static class Group implements Serializable {

		private static final long serialVersionUID = -7632495076167305521L;
		
		private String groupName;
		private String owner;
		private LinkedList<String> memberName;
		private LinkedList<Integer> memberRoll;
		private LinkedList<Integer> memberStatus;
		private boolean groupDeleted;
		
		public Group() {
			memberName = new LinkedList<String>();
			memberRoll = new LinkedList<Integer>();
			memberStatus = new LinkedList<Integer>();
			setGroupDeleted(false);
		}
		
		public String getGroupName() {
			return groupName;
		}
		public Group setGroupName(String groupName) {
			this.groupName = groupName;
			return this;
		}
		public String getOwner() {
			return owner;
		}
		public Group setOwner(String owner) {
			this.owner = owner;
			return this;
		}
		
		public LinkedList<GroupMember> getMembers() {
			LinkedList<GroupMember> members = new LinkedList<GroupMember>();
			for(int i = 0; i < memberName.size(); i++) {
				members.add(new GroupMember(memberName.get(i), memberStatus.get(i), memberRoll.get(i)));
			}
			return members;
		}
		public Group setMembers(LinkedList<GroupMember> members) {
			memberName = new LinkedList<String>();
			memberStatus = new LinkedList<Integer>();
			memberRoll = new LinkedList<Integer>();
			for(int i = 0; i < members.size(); i++) {
				memberName.add(members.get(i).getGroupMemberUser());
				memberStatus.add(members.get(i).getGroupMemberStatus());
				memberRoll.add(members.get(i).getGroupMemberRoll());
			}
			return this;
		}
		public Group addMember(GroupMember member) {
			memberName.add(member.getGroupMemberUser());
			memberStatus.add(member.getGroupMemberStatus());
			memberRoll.add(member.getGroupMemberRoll());
			return this;
		}

		public Group setGroupDeleted(boolean groupDeleted) {
			this.groupDeleted = groupDeleted;
			return this;
		}

		public boolean isGroupDeleted() {
			return groupDeleted;
		}

		public LinkedList<String> getMemberName() {
			return memberName;
		}

		public void setMemberName(LinkedList<String> memberName) {
			this.memberName = memberName;
		}

		public LinkedList<Integer> getMemberRoll() {
			return memberRoll;
		}

		public void setMemberRoll(LinkedList<Integer> memberRoll) {
			this.memberRoll = memberRoll;
		}

		public LinkedList<Integer> getMemberStatus() {
			return memberStatus;
		}

		public void setMemberStatus(LinkedList<Integer> memberStatus) {
			this.memberStatus = memberStatus;
		}
	}
	
	public static class Task implements Serializable {

		private static final long serialVersionUID = -5322928818841142270L;

		private long global_id;
		private int local_id;
		private String name;
		private String notes;
		private String location;
		private String owner;
		private LinkedList<String> assignedList;
		private long global_parent;
		private int due_date;
		private int due_time;
		private int percent_complete;
		private int done;
		private int priority;
		private long timestamp;
		
		public Task() {};
		
		public long getGlobal_id() {
			return global_id;
		}
		public Task setGlobal_id(long l) {
			global_id = l;
			return this;
		}
		public int getLocal_id() {
			return local_id;
		}
		public Task setLocal_id(int localId) {
			local_id = localId;
			return this;
		}
		public String getName() {
			return name;
		}
		public Task setName(String name) {
			this.name = name;
			return this;
		}
		public String getNotes() {
			return notes;
		}
		public Task setNotes(String notes) {
			this.notes = notes;
			return this;
		}
		public String getLocation() {
			return location;
		}
		public Task setLocation(String location) {
			this.location = location;
			return this;
		}
		public long getGlobal_parent() {
			return global_parent;
		}
		public Task setGlobal_parent(long globalParent) {
			global_parent = globalParent;
			return this;
		}
		public int getDue_date() {
			return due_date;
		}
		public Task setDue_date(int dueDate) {
			due_date = dueDate;
			return this;
		}
		public int getDue_time() {
			return due_time;
		}
		public Task setDue_time(int dueTime) {
			due_time = dueTime;
			return this;
		}
		public int getPercent_complete() {
			return percent_complete;
		}
		public Task setPercent_complete(int percentComplete) {
			percent_complete = percentComplete;
			return this;
		}
		public int getDone() {
			return done;
		}
		public Task setDone(int done) {
			this.done = done;
			return this;
		}
		public int getPriority() {
			return priority;
		}
		public Task setPriority(int priority) {
			this.priority = priority;
			return this;
		}

		public long getTimestamp() {
			return timestamp;
		}

		public Task setTimestamp(long timestamp) {
			this.timestamp = timestamp;
			return this;
		}

		public Task setAssignedList(LinkedList<String> assignedList) {
			this.assignedList = assignedList;
			return this;
		}

		public LinkedList<String> getAssignedList() {
			return assignedList;
		}

		public void setOwner(String owner) {
			this.owner = owner;
		}

		public String getOwner() {
			return owner;
		}
	};
	
	public static class MessageToServer implements Serializable {

		private static final long serialVersionUID = 3557059889104041069L;

		private ResponseType response;
		private String user;
		private String password;
		private ActionType action = ActionType.POLL;
		private String contact_user;
		private Messages.Task task;
		private Messages.Group group;
		private String phone_number;
		private String email;
		private String uuid;
		private int access_level;
		private String name;
		private long lastModifiedTime;
		
		public MessageToServer() {
			group = new Group();
		}
		
		public String getUser() {
			return user;
		}
		
		public MessageToServer setUser(String user) {
			this.user = user;
			return this;
		}
		
		public String getPassword() {
			return password;
		}
		
		public MessageToServer setPassword(String password) {
			this.password = password;
			return this;
		}
		
		public ActionType getAction() {
			return action;
		}
		
		public MessageToServer setAction(ActionType action) {
			this.action = action;
			return this;
		}
		
		public String getContact_user() {
			return contact_user;
		}
		
		public MessageToServer setContact_user(String contactUser) {
			contact_user = contactUser;
			return this;
		}
		
		public Messages.Task getTask() {
			return task;
		}
		
		public MessageToServer addTask(Messages.Task task) {
			this.task = task;
			return this;
		}
		
		public Messages.Group getGroup() {
			return group;
		}

		public MessageToServer setGroup(Messages.Group group) {
			this.group = group;
			return this;
		}

		public ResponseType getResponse() {
			return response;
		}

		public MessageToServer setResponse(ResponseType response) {
			this.response = response;
			return this;
		}

		public String getPhone_number() {
			return phone_number;
		}

		public MessageToServer setPhone_number(String phoneNumber) {
			phone_number = phoneNumber;
			return this;
		}

		public String getEmail() {
			return email;
		}

		public MessageToServer setEmail(String email) {
			this.email = email;
			return this;
		}

		public String getUuid() {
			return uuid;
		}

		public MessageToServer setUuid(String uuid) {
			this.uuid = uuid;
			return this;
		}

		public int getAccess_level() {
			return access_level;
		}

		public MessageToServer setAccess_level(int accessLevel) {
			access_level = accessLevel;
			return this;
		}

		public String getName() {
			return name;
		}

		public MessageToServer setName(String name) {
			this.name = name;
			return this;
		}

		public long getLastModifiedTime() {
			return lastModifiedTime;
		}

		public MessageToServer setLastModifiedTime(long lastModifiedTime) {
			this.lastModifiedTime = lastModifiedTime;
			return this;
		}
	};
	
	public static class MessageToClient implements Serializable {

		private static final long serialVersionUID = 3557059889104041069L;

		private ResponseType response;
		private String user;
		private ActionType action = ActionType.POLL;
		private String contact_user;
		private String group_name;
		private long lastModified;
		private LinkedList<Messages.Group> groups;
		private LinkedList<Messages.Task> tasks;
		private LinkedList<Messages.User> group_users;
		private LinkedList<Messages.User> users;
		private LinkedList<Messages.User> addedContacts;
		private LinkedList<Messages.User> requestedContacts;
		private LinkedList<Messages.User> removedContacts;
		private LinkedList<Messages.Task> updatedTasks;
		private LinkedList<Messages.Task> removedTasks;
		private String uuid;
		
		public MessageToClient() {
			groups = new LinkedList<Messages.Group>();
			tasks = new LinkedList<Messages.Task>();
			group_users = new LinkedList<Messages.User>();
			users = new LinkedList<Messages.User>();
			addedContacts = new LinkedList<Messages.User>();
			requestedContacts = new LinkedList<Messages.User>();
			removedContacts = new LinkedList<Messages.User>();
			updatedTasks = new LinkedList<Messages.Task>();
			removedTasks = new LinkedList<Messages.Task>();
		}
		
		public String getUser() {
			return user;
		}
		
		public MessageToClient setUser(String user) {
			this.user = user;
			return this;
		}
		
		public ActionType getAction() {
			return action;
		}
		
		public MessageToClient setAction(ActionType action) {
			this.action = action;
			return this;
		}
		
		public String getContact_user() {
			return contact_user;
		}
		
		public MessageToClient setContact_user(String contactUser) {
			contact_user = contactUser;
			return this;
		}
		
		public String getGroup_name() {
			return group_name;
		}
		
		public MessageToClient setGroup_name(String groupName) {
			group_name = groupName;
			return this;
		}
		
		public LinkedList<Messages.Task> getTasks() {
			return tasks;
		}
		
		public MessageToClient setTasks(LinkedList<Messages.Task> tasks) {
			this.tasks = tasks;
			return this;
		}
		
		public MessageToClient addTask(Messages.Task task) {
			this.tasks.add(task);
			return this;
		}
		
		public LinkedList<Messages.User> getGroup_users() {
			return group_users;
		}
		
		public MessageToClient setGroup_users(LinkedList<Messages.User> groupUsers) {
			group_users = groupUsers;
			return this;
		}
		
		public MessageToClient addGroup_users(Messages.User user) {
			group_users.add(user);
			return this;
		}

		public ResponseType getResponse() {
			return response;
		}

		public MessageToClient setResponse(ResponseType response) {
			this.response = response;
			return this;
		}
		
		public String getUuid() {
			return uuid;
		}

		public MessageToClient setUuid(String uuid) {
			this.uuid = uuid;
			return this;
		}

		public LinkedList<Messages.User> getUsers() {
			return users;
		}

		public void setUsers(LinkedList<Messages.User> users) {
			this.users = users;
		}
		
		public void addUser(Messages.User user) {
			this.users.add(user);
		}

		public LinkedList<Messages.User> getAddedContacts() {
			return addedContacts;
		}
		
		public void addAddedContact(Messages.User user) {
			this.addedContacts.add(user);
		}

		public void setAddedContacts(LinkedList<Messages.User> addedContacts) {
			this.addedContacts = addedContacts;
		}

		public LinkedList<Messages.User> getRequestedContacts() {
			return requestedContacts;
		}
		
		public void addRequestedContact(Messages.User user) {
			this.requestedContacts.add(user);
		}

		public void setRequestedContacts(LinkedList<Messages.User> requestedContacts) {
			this.requestedContacts = requestedContacts;
		}

		public LinkedList<Messages.User> getRemovedContacts() {
			return removedContacts;
		}
		
		public void addRemovedContact(Messages.User user) {
			this.removedContacts.add(user);
		}

		public void setRemovedContacts(LinkedList<Messages.User> removedContacts) {
			this.removedContacts = removedContacts;
		}
		
		public LinkedList<Messages.Task> getUpdatedTasks() {
			return updatedTasks;
		}
		
		public void addUpdatedTask(Messages.Task task) {
			this.updatedTasks.add(task);
		}

		public void setUpdatedTasks(LinkedList<Messages.Task> updatedTasks) {
			this.updatedTasks = updatedTasks;
		}
		
		public LinkedList<Messages.Task> getRemovedTasks() {
			return removedTasks;
		}
		
		public void addRemovedTask(Messages.Task task) {
			this.removedTasks.add(task);
		}

		public MessageToClient setRemovedTasks(LinkedList<Messages.Task> removedTasks) {
			this.removedTasks = updatedTasks;
			return this;
		}

		public MessageToClient setLastModified(long lastModified) {
			this.lastModified = lastModified;
			return this;
		}

		public long getLastModified() {
			return lastModified;
		}

		public MessageToClient setGroups(LinkedList<Messages.Group> groups) {
			this.groups = groups;
			return this;
		}
		
		public MessageToClient addGroup(Messages.Group group) {
			this.groups.add(group);
			return this;
		}

		public LinkedList<Messages.Group> getGroups() {
			return groups;
		}
	};
}
